/**
  ******************************************************************************
  * @file    can_app.c
  * @author  vincent
  * @version V3.5.0
  * @date    2018/10/09
  * @brief   This file provides main functions.
  ******************************************************************************
  * @attention
  *
  * 
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "usb2can_driver.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>



#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
/* prama define discrible -----------------------------------------------------*/


/* Ptrcuct  discrible --------------------------------------------------------*/


/* Prama  discrible ---------------------------------------------------------*/

can_device my_device;

/* Private fucntion  declaration --------------------------------------------*/



/******************************************************************************
* @Function:  
* @Discrible:   
* @Param:  
* @Return:   
* @Others: 
******************************************************************************
* @Recode    date       version	        author             modify 
*          ------------------------------------------------------------------
*          20181009      V1.0          VINCENT            Create
* 
*******************************************************************************/
int main(char argc,char*argv[])
{
    function ret = 0;
    unsigned char buf[8] = {0x25,0x23,0,0,0,0,0,0};
    unsigned int err_code = 0;
    struct timeval tv;
    can_msg_package myrecive = {0};
    can_msg_package mytransmit;

    mytransmit.total_count = 1;
    mytransmit.can_msg_buf[0].id=0x01;
    mytransmit.can_msg_buf[0].len=8;
    memcpy(mytransmit.can_msg_buf[0].msg,buf,8);
    static int count = 0;

    for(int i = 0;i<=sizeof(buf);i++)
    {
        buf[i]=i;
    }
    my_device = device_can_init();

    ret = device_can_open(my_device,&err_code);

    if(statu_ok == ret)
    {
        printf("------------------she bei da kai cheng gong------------ \r\n");
    }
    else
    {
        printf("------------------she bei da kai shi bai------------ \r\n");
        return 0;
    }
    

    while(1)
    {
        device_can_write_msg(my_device,&mytransmit);
        device_can_read_msg(my_device,&myrecive);
        if(myrecive.total_count > 0)
        {   
            printf("\n-----------------recive:%d-------------\n",myrecive.total_count);
            
            for(int i = 0; i< myrecive.total_count;i++)
            {
                count++;
                printf("%d    ID: 0X%X    len: %d  ",count,myrecive.can_msg_buf->id,myrecive.can_msg_buf->len);
                for(int j = 0; j< myrecive.can_msg_buf->len;j++)
                {
                    printf("0X%X ",myrecive.can_msg_buf->msg[j]);
                }
                printf("\r\n");
            }
        }
        usleep(1000*20);  
    }
    
    return 0;
}

/* private fucntion  discrible -----------------------------------------------*/

/************************ (C) END OF FILE ************************************/








